package com.test;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

import com.alibaba.dubbo.common.json.JSONArray;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.guo.hui.dao.blog.TpArticleMapper;
import com.guo.hui.dao.blog.TpCommentMapper;
import com.guo.hui.dao.blog.TpTimelineMapper;
import com.guo.hui.dao.shiro.TpUserMapper;
import com.guo.hui.model.blog.TpComment;
import com.guo.hui.model.mobile.MyUser;
import com.guo.hui.util.UtilJson;

@ContextConfiguration(locations = { "classpath:spring-mybatis.xml" })
public class UnitArticle extends AbstractJUnit4SpringContextTests {
	@Autowired
	private TpArticleMapper articleDao;
	@Autowired
	private TpTimelineMapper lineDao;
	@Autowired
	private TpUserMapper userDao;
	@Autowired
	private TpCommentMapper commentDao;

	@Test
	public void test1() {
		List<MyUser> list = new ArrayList<>();
		List<MyUser> list1 = new ArrayList<>();
		MyUser user = new MyUser();
		user.setId(1);
		user.setUsername("国辉");
		user.setPassword("123456");
		MyUser user1 = new MyUser();
		user1.setId(2);
		user1.setUsername("zixian");
		user1.setPassword("654321");
		list.add(user);
		list.add(user1);
		String jsonstr = UtilJson.toJson(list);
		Gson gson = new Gson();
		// json转为带泛型的list
		List<MyUser> retList1 = UtilJson.fromJsonType(jsonstr, new TypeToken<List<MyUser>>() {
		}.getType());
//		List<MyUser> retList = gson.fromJson(jsonstr, new TypeToken<List<MyUser>>() {
//		}.getType());
		System.out.println(retList1);
	}

	@Test
	public void test() {
		// Map<String, Object> map = new HashMap<>();
		// List<TpComment> comment = commentDao.selectByMap(map);
		// System.out.println(comment);
		// TpAdmin tpAdmin = new TpAdmin();
		// tpAdmin.setId(21);
		// tpAdmin.setUsername("admin");
		// tpAdmin.setPassword("admin");
		// adminDao.update(tpAdmin);
		// articleDao.selectByMap(map);
		// TpUser tpUser = new TpUser();
		// tpUser.setUsercode("guohui");
		// tpUser.setUsername("guohui");
		// tpUser.setPassword("guohui");
		// userDao.insert(tpUser);
		// System.out.println(articleDao.selectByMap(map));
		// int kk = 19;
		// System.out.println(kk / 5 + 1);
	}

}
